﻿Imports Microsoft.Win32
Imports Microsoft.VisualBasic
Imports System.Math

Public Class frmCnfg

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        'Save the current settings to
        'HKEY_CURRENT_USER\Software\
        'in the registry.

        
        Dim col1, col2, col3, col4 As Listas
        If rbPublic1.Checked Then col1 = Listas.PublicTimeline
        If rbPublic2.Checked Then col2 = Listas.PublicTimeline
        If rbPublic3.Checked Then col3 = Listas.PublicTimeline
        If rbPublic4.Checked Then col4 = Listas.PublicTimeline

        If rbFriends1.Checked Then col1 = Listas.Friends
        If rbFriends2.Checked Then col2 = Listas.Friends
        If rbFriends3.Checked Then col3 = Listas.Friends
        If rbFriends4.Checked Then col4 = Listas.Friends

        If rbReply1.Checked Then col1 = Listas.Reply
        If rbReply2.Checked Then col2 = Listas.Reply
        If rbReply3.Checked Then col3 = Listas.Reply
        If rbReply4.Checked Then col4 = Listas.Reply

        If rbUser1.Checked Then col1 = Listas.User
        If rbUser2.Checked Then col2 = Listas.User
        If rbUser3.Checked Then col3 = Listas.User
        If rbUser4.Checked Then col4 = Listas.User

        If rbNada1.Checked Then col1 = Listas.None
        If rbNada2.Checked Then col2 = Listas.None
        If rbNada3.Checked Then col3 = Listas.None
        If rbNada4.Checked Then col4 = Listas.None

        If rbDirect1.Checked Then col1 = Listas.DirectMessages
        If rbDirect2.Checked Then col2 = Listas.DirectMessages
        If rbDirect3.Checked Then col3 = Listas.DirectMessages
        If rbDirect4.Checked Then col4 = Listas.DirectMessages


        Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software", True)
        Dim newkey As RegistryKey = key.CreateSubKey("TwittScreenSaver")
        newkey.SetValue("Usuario", txtUser.Text)
        newkey.SetValue("Pwd", txtPasswd.Text)
        newkey.SetValue("Col1", CInt(col1))
        newkey.SetValue("Col2", CInt(col2))
        newkey.SetValue("Col3", CInt(col3))
        newkey.SetValue("Col4", CInt(col4))
        newkey.SetValue("Refresh", CInt(txtRecargar.Text))
        newkey.Close()

        Me.Close()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Me.Close()
    End Sub

    Public Enum Listas
        PublicTimeline
        Friends
        Reply
        DirectMessages
        User
        None
    End Enum

    Private Sub frmCnfg_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim key As RegistryKey = Registry.CurrentUser.OpenSubKey("Software", True)
        Dim newkey As RegistryKey = key.CreateSubKey("TwittScreenSaver")
        txtUser.Text = newkey.GetValue("Usuario")
        txtPasswd.Text = newkey.GetValue("Pwd")
        Select Case CType(newkey.GetValue("Col1"), Listas)
            Case Listas.PublicTimeline
                rbPublic1.Checked = True
            Case Listas.Friends
                rbFriends1.Checked = True
            Case Listas.Reply
                rbReply1.Checked = True
            Case Listas.DirectMessages
                rbDirect1.Checked = True
            Case Listas.User
                rbUser1.Checked = True
            Case Listas.None
                rbNada1.Checked = True
        End Select
        Select Case CType(newkey.GetValue("Col2"), Listas)
            Case Listas.PublicTimeline
                rbPublic2.Checked = True
            Case Listas.Friends
                rbFriends2.Checked = True
            Case Listas.Reply
                rbReply2.Checked = True
            Case Listas.DirectMessages
                rbDirect2.Checked = True
            Case Listas.User
                rbUser2.Checked = True
            Case Listas.None
                rbNada2.Checked = True
        End Select
        Select Case CType(newkey.GetValue("Col3"), Listas)
            Case Listas.PublicTimeline
                rbPublic3.Checked = True
            Case Listas.Friends
                rbFriends3.Checked = True
            Case Listas.Reply
                rbReply3.Checked = True
            Case Listas.DirectMessages
                rbDirect3.Checked = True
            Case Listas.User
                rbUser3.Checked = True
            Case Listas.None
                rbNada3.Checked = True
        End Select
        Select Case CType(newkey.GetValue("Col4"), Listas)
            Case Listas.PublicTimeline
                rbPublic4.Checked = True
            Case Listas.Friends
                rbFriends4.Checked = True
            Case Listas.Reply
                rbReply4.Checked = True
            Case Listas.DirectMessages
                rbDirect4.Checked = True
            Case Listas.User
                rbUser4.Checked = True
            Case Listas.None
                rbNada4.Checked = True
        End Select
        Dim refresh As Integer
        refresh = newkey.GetValue("refresh")
        If refresh = 0 Then refresh = 5
        txtRecargar.Text = refresh
        newkey.Close()
    End Sub
End Class

